package com.interview.rtc.aigc.common;

import lombok.Data;

@Data
public class ResponseResult<T> {
    private Integer code;
    private String message;
    private T data;

    public ResponseResult(Integer code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public static <T> ResponseResult<T> success(T data) {
        return new ResponseResult<>(200, "success", data);
    }
    public static <T> ResponseResult<T> success() {
        return new ResponseResult<>(200, "success",null);
    }

    public static <T> ResponseResult<T> success(String message, T data) {
        return new ResponseResult<>(200, message, data);
    }

    public static <T> ResponseResult<T> error(String message) {
        return new ResponseResult<>(500, message, null);
    }

    public static <T> ResponseResult<T> error(Integer code, String message) {
        return new ResponseResult<>(code, message, null);
    }
    
    /**
     * 带有错误详情的错误响应
     *
     * @param code    错误码
     * @param message 错误消息
     * @param data    错误详情
     * @param <T>     错误详情类型
     * @return 响应结果
     */
    public static <T> ResponseResult<T> error(Integer code, String message, T data) {
        return new ResponseResult<>(code, message, data);
    }
    
    /**
     * 从业务异常创建错误响应
     *
     * @param e   业务异常
     * @param <T> 数据类型
     * @return 响应结果
     */
    public static <T> ResponseResult<T> error(BusinessException e) {
        return new ResponseResult<>(e.getCode(), e.getMessage(), null);
    }
    
    /**
     * 使用错误码创建错误响应
     *
     * @param errorCode 错误码
     * @param message   错误消息
     * @param <T>       数据类型
     * @return 响应结果
     */
    public static <T> ResponseResult<T> errorWithCode(int errorCode, String message) {
        return new ResponseResult<>(errorCode, message, null);
    }
}
